<extend name="_layout/main" />
<block name="head">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/assets/css/jasny-bootstrap.min.css" />
    <style type="text/css">
        #thumb~i
        {
            display: none!important;
        }
    </style>
</block>
<block name="content">
    <div class="page-content">
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>
                    <a href="{:U('dashboard/index')}">系统首页</a>
                </li>
                <li>
                    <a href="javascript:;">活动管理</a>
                </li>
                <li class="active">编辑活动</li>
            </ul>
        </div>
        <div class="page-body">
            <div class="row">
                <div class="col-xs-12 col-md-12">
                    <div class="widget">
                        <div class="widget-header">
                            <span class="widget-caption">编辑活动</span>
                        </div>
                        <div class="widget-body">
                            <div>
                                <div class="tabbable">
                                    <ul class="nav nav-tabs" id="myTab">
                                        <li class="active">
                                            <a data-toggle="tab" href="#home" aria-expanded="true">
                                                基本信息
                                            </a>
                                        </li>

                                    </ul>
                                    <form role="form" class="form-horizontal" method="post" id="addForm" enctype="multipart/form-data">
                                        <input type="hidden" id="id" name="id" value="{$id}"  />
                                        <div class="tab-content">
                                            <div id="home" class="tab-pane active">
                                                <div class="form-group ">
                                                    <label for="activity_name" class="col-sm-2 control-label no-padding-right">活动名称</label>
                                                    <div class="col-xs-4">
                                                        <input type="text" class="form-control" id="activity_name" name="activity_name" value="{$activity_name}">
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="status" class="col-sm-2 control-label no-padding-right">活动状态</label>
                                                    <div class="col-xs-4">
                                                        <select class="form-control" id="status" name="status">
                                                            <option  value="1" <eq name="status" value="1">selected="selected"</eq> >有效</option>
                                                            <option value="0" <eq name="status" value="0">selected="selected"</eq> >过期/无效</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="activity_name" class="col-sm-2 control-label no-padding-right">活动时间</label>
                                                    <div class="col-xs-4">
                                                        <input type="hidden" name="begin_time" id="begin_time" value="{:date('m/d/Y',$begin_time)}" />
                                                        <input type="hidden" name="end_time" id="end_time" value="{:date('m/d/Y',$end_time)}" />
                                                        <input type="text" class="form-control" id="range_time" name="range_time" placeholder="开始时间" value="{:date('m/d/Y',$begin_time)} - {:date('m/d/Y',$end_time)}">
                                                    </div>
                                                </div>

                                                <div class="form-group ">
                                                    <label for="show_index" class="col-sm-2 control-label no-padding-right">显示在首页</label>
                                                    <div class="col-xs-4">
                                                        <select class="form-control" id="show_index" name="show_index">
                                                            <option value="1" <eq name="show_index" value="1">selected="selected"</eq> >显示</option>
                                                            <option value="0" <eq name="show_index" value="0">selected="selected"</eq> >不显示</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="status" class="col-sm-2 control-label no-padding-right">是否推荐</label>
                                                    <div class="col-xs-4">
                                                        <select class="form-control" id="recommend" name="recommend">
                                                            <option  value="1" <eq name="recommend" value="1">selected="selected"</eq> >推荐</option>
                                                            <option value="0" <eq name="recommend" value="0">selected="selected"</eq> >不推荐</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group ">
                                                    <label for="thumb" class="col-sm-2 control-label no-padding-right">封面图</label>
                                                    <div class="col-xs-4">
                                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                                            <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;"> <img src="{$thumb}" data-src="holder.js/200x150?text=封面&theme=gray"> </div>
                                                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                                                            <div> <span class="btn btn-default btn-file"><span class="fileinput-new">上传</span> <span class="fileinput-exists">重新上传</span>
																<input type="file" name="thumb" id="thumb">
																</span> <a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">删除</a> </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label for="summary" class="col-sm-2 control-label no-padding-right">摘要</label>
                                                    <div class="col-xs-6">
                                                        <textarea class="form-control" rows="5" name="activity_summary">{$activity_summary}</textarea>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="content" class="col-sm-2 control-label no-padding-right">内容</label>
                                                    <div class="col-xs-6">
                                                        <?php echo form::editor('activity_content',htmlspecialchars_decode(stripslashes($activity_content)),'full')?>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-sm-offset-2 col-sm-10">
                                                    <button type="submit" class="btn btn-blue ladda-button" data-style="expand-right" id="submitBtn"> <span class="ladda-label">确认保存</span></button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="footer">

    <script src="__PUBLIC__/assets/js/validation/bootstrapValidator.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/select2/select2.js"></script>
    <script src="__PUBLIC__/assets/js/holder.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/jasny-bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/datetime/moment.js"></script>
    <script src="__PUBLIC__/assets/js/datetime/zh-cn.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/assets/js/datetime/daterangepicker.js"></script>
    <script type="text/javascript">
        moment.lang('zh-cn');
        $('#range_time').daterangepicker({
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消'
            },
            startDate:"{:date('m/d/Y', $begin_time)}",
            endDate:"{:date('m/d/Y',$end_time)}"
        },function(start,end,label){
            $("#begin_time").val(start.format('MM/DD/YYYY'));
            $("#end_time").val(end.format('MM/DD/YYYY'));
        });

        var loader = Ladda.create(document.getElementById("submitBtn"));
        $("#addForm").bootstrapValidator({
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function(validator, form, submitButton) {
                loader.start();
                $("#addForm").ajaxSubmit(function(result) {
                    loader.stop();
                    result = JSON.parse(result);
                    if (result.status == 'success') {
                        location.href = "{:U('activity')}";
                    } else {
                        tips(result.message, 'danger');
                        validator.disableSubmitButtons(false);
                    }
                });
            },
            fields: {
                activity_name: {
                    validators: {
                        notEmpty: {
                            message: '活动名称不能为空'
                        }
                    }
                },
            }
        });
    </script>
</block>